package org.kl.bf.entity.basic;

import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.kl.bf.entity.AuditableEntity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * 日程管理
 * 
 * @Author hqm
 * @CreateTime 2014年6月22日 上午12:32:52
 */
// JPA标识
@Entity
@Table(name = "basic_calendar")
public class Calendar extends AuditableEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = 5797917084709511854L;
	private User user;
	private CalendarType calendarType;
	private String title;// 标题
	private Integer allDay;// 是否全天事件
	private Timestamp start;// 开始时间
	private Timestamp end;// 截止时间
	private String url;// 事件链接
	private String className;// 事件样式
	private Integer editable;// 是否可编辑
	private String color;// 背景和边框颜色
	private String backgroundColor;// 背景颜色
	private String borderColor;// 边框颜色
	private String textColor;// 文本颜色

	@SuppressWarnings("unused")
	private boolean bAllDay;
	@SuppressWarnings("unused")
	private boolean bEditable;

	public Calendar() {
	}

	public Calendar(String id) {
		this.id = id;
	}

	@ManyToOne
	@JoinColumn(name = "user_id")
	@JsonIgnore
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@ManyToOne
	@JoinColumn(name = "type_id")
	public CalendarType getCalendarType() {
		return calendarType;
	}

	public void setCalendarType(CalendarType calendarType) {
		this.calendarType = calendarType;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	@JsonIgnore
	public Integer getAllDay() {
		return allDay;
	}

	public void setAllDay(Integer allDay) {
		this.allDay = allDay;
	}

	// 设定JSON序列化时的日期格式
	@Column(name = "start_time")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Timestamp getStart() {
		return start;
	}

	public void setStart(Timestamp start) {
		this.start = start;
	}

	// 设定JSON序列化时的日期格式
	@Column(name = "end_time")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Timestamp getEnd() {
		return end;
	}

	public void setEnd(Timestamp end) {
		this.end = end;
	}

	@JsonIgnore
	public Integer getEditable() {
		return editable;
	}

	public void setEditable(Integer editable) {
		this.editable = editable;
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	public String getBackgroundColor() {
		return backgroundColor;
	}

	public void setBackgroundColor(String backgroundColor) {
		this.backgroundColor = backgroundColor;
	}

	public String getBorderColor() {
		return borderColor;
	}

	public void setBorderColor(String borderColor) {
		this.borderColor = borderColor;
	}

	public String getTextColor() {
		return textColor;
	}

	public void setTextColor(String textColor) {
		this.textColor = textColor;
	}

	@Transient
	@JsonProperty("allDay")
	public boolean isbAllDay() {
		if (this.allDay != null && this.allDay == 1)
			return true;
		else
			return false;
	}

	@Transient
	@JsonProperty("editable")
	public boolean isbEditable() {
		if (this.editable != null && this.editable == 0)
			return false;
		else
			return true;
	}

}
